﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using AutoChess;
public class PlayerInfoItemEx : MonoBehaviour
{
    public GameObject outRoot;
    public PlayerInfoListPanel panel;
    public TextureKit shipIcon;
    public Text playerName;
    public Slider slider;
    public GroupSpriteKit sliderKit;
    public UGUITweenPosition tweenPos;
    private long playerGuid;
    public void Init(ACPlayerData player)
    {
        playerGuid = player.GUID;
        shipIcon.TextureName = UtilityHelper.GetShipIcon(player);
        playerName.text = player.NickName;
        slider.value = player.HP * 1f / 100;
        sliderKit.SetSpriteName(player.IsSeeSelf? "UI_xinxi_shengmingjindutiao":"UI_jiesuan_jindu_exp");
        outRoot.SetActive(player.IsDeath);
    }

    public void PlayTween(Vector3 pos, ACPlayerData player)
    {
        tweenPos.from = transform.localPosition;
        tweenPos.to = pos;
        tweenPos.duration = 0.4f;
        tweenPos.PlayForward();
        Init(player);
    }

    public void SwitchHero()
    {
        var playerData = AutoChessManager.Ins.cacheData.GetPlayerData(playerGuid);
        if (playerData.GUID == AutoChessManager.Ins.cacheData.CurPlayerData.GUID)
            return;
        if (playerData.HP <= 0)
        {
            MessageBoxManager.Instance.CreatePopupWordTip(TableTextBlo.GetText("ac_player_death"));
            return;
        }
        AutoChessManager.Ins.SwitchToPlayer(playerGuid);
        panel.ClosePanel();
    }
}
